<?php
namespace Shopmobile\Model;
use Think\Model;
class UsersGiftsModel extends Model{
	public $sid;
	public $eid;
	public $shop_uid;
	public $mygifts;
	public function getMyGifts(){
		$ugwh["sid"]=$this->sid;
		$ugwh["eventid"]=$this->eid;
		$ugwh["uzuid"]=$this->shop_uid;
		//PC端多读取2个字段：gift_pic_url、details
		$mygifts = $this->where($ugwh)->getField("`id`,`id`,`actiontime`,`giftid`,`gtype`,`kamiid`,`wlid`,`wlcode`,`getway`,`is_picup`,`picup_time`,`gift_name`,`gift_pic_url`");
		$mygifts = array_values($mygifts);
		$gtype = C("GFT_TYPE");//->order("id desc")
		foreach($mygifts as $k=>$gift){
			foreach($gtype as $gk=>$gt){
				if($gift["gtype"]==$gt["id"]){
					$gift["gtype_name"]=$mygifts[$k]["gtype_name"]=$gt["name"];
					$gift["gtype_code"]=$mygifts[$k]["gtype_code"]=$gk;
				}
				if($gift["is_picup"]==1 && $gift["gtype"]==$gtype["zfbhb"]["id"]){
					$KM = M("GiftsKm");
					$km = current($KM->where("`sid`=".$this->sid." AND `user_giftid`=".$gift["id"]." AND `status`=9")->limit(1)->getField("`id`,`cardno`,`secret`"));
					$gift["km"] = $mygifts[$k]["km"]=$km;
				}
			}
			
			
			if($gift["is_picup"] && !$gift["km"] && $gift["gtype_code"]!='item')
			{
				$mygifts[$k]["param"]["disabled"]="disabled";
			}
			
			if(($gift["is_picup"] && $gift["km"]) ||  ($gift["is_picup"] && $gift["gtype_code"]=='item'))
			{
				$mygifts[$k]["param"]["class"]="show";
			}
			
			if ($gift["km"])
			{
				$mygifts[$k]["param"]["data-cardno"]=$gift["km"]["cardno"];
				$mygifts[$k]["param"]["data-secret"]=$gift["km"]["secret"];
			}
			
			if ($gift["km"])
			{
				$mygifts[$k]["param"]["value"]="查看卡密";
			}
			elseif($gift["is_picup"] && $gift["gtype_code"]=='item')
			{
				$mygifts[$k]["param"]["value"]="查看物流";
			}
			else
			{
				if($gift["is_picup"])
				{
					$mygifts[$k]["param"]["value"]="已经";
				}
				$mygifts[$k]["param"]["value"].="领取".$gift["gtype_name"];
			}
			
			if ($gift["is_picup"] && $gift["gtype_code"]=='item')
			{
				$mygifts[$k]["param"]["data-getway"] = "checkwl";
			}
			elseif($gift["km"])
			{
				$mygifts[$k]["param"]["data-getway"] = "look";
			}
			else
			{
				$mygifts[$k]["param"]["data-getway"] = $mygifts[$k]["getway"];
			}
		}
		$this->mygifts = $mygifts;
	}
}